<?php
date_default_timezone_set("Asia/Shanghai");
class ControllerAccountOrder extends Controller {
	private $error = array();

	public function index() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->link('account/order', '', 'SSL');

			$this->redirect($this->url->link('account/login', '', 'SSL'));
		}

		$this->language->load('account/order');

		$this->load->model('account/order');
        $this->load->model('catalog/product');
        $this->load->model('tool/image');

		if (isset($this->request->get['order_id'])) {
			$order_info = $this->model_account_order->getOrder($this->request->get['order_id']);

			if ($order_info) {
				$order_products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);

				foreach ($order_products as $order_product) {
					$option_data = array();

					$order_options = $this->model_account_order->getOrderOptions($this->request->get['order_id'], $order_product['order_product_id']);

					foreach ($order_options as $order_option) {
						if ($order_option['type'] == 'select' || $order_option['type'] == 'radio') {
							$option_data[$order_option['product_option_id']] = $order_option['value'];
						} elseif ($order_option['type'] == 'checkbox') {
							$option_data[$order_option['product_option_id']][] = $order_option['value'];
						} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
							$option_data[$order_option['product_option_id']] = $order_option['value'];
						} elseif ($order_option['type'] == 'file') {
							$option_data[$order_option['product_option_id']] = $this->encryption->encrypt($order_option['value']);
						}
					}


					$this->session->data['success'] = sprintf($this->language->get('text_success'), $this->request->get['order_id']);

					$this->cart->add($order_product['product_id'], $order_product['quantity'], $option_data);
				}

				$this->redirect($this->url->link('checkout/cart'));
			}
		}

		$this->document->setTitle($this->language->get('heading_title'));

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_account'),
			'href'      => $this->url->link('account/account', '', 'SSL'),
			'separator' => $this->language->get('text_separator')
		);

		$url = '';

		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('account/order', $url, 'SSL'),
			'separator' => $this->language->get('text_separator')
		);

		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_order_id'] = $this->language->get('text_order_id');
		$this->data['text_status'] = $this->language->get('text_status');
		$this->data['text_date_added'] = $this->language->get('text_date_added');
		$this->data['text_customer'] = $this->language->get('text_customer');
		$this->data['text_products'] = $this->language->get('text_products');
		$this->data['text_total'] = $this->language->get('text_total');
		$this->data['text_empty'] = $this->language->get('text_empty');


        $this->data['column_name'] = $this->language->get('column_name');
        $this->data['column_model'] = $this->language->get('column_model');
        $this->data['column_quantity'] = $this->language->get('column_quantity');
        $this->data['column_price'] = $this->language->get('column_price');
        $this->data['column_total'] = $this->language->get('column_total');
        $this->data['column_action'] = $this->language->get('column_action');
        $this->data['column_date_added'] = $this->language->get('column_date_added');
        $this->data['column_status'] = $this->language->get('column_status');
        $this->data['column_comment'] = $this->language->get('column_comment');
        $this->data['column_description'] = $this->language->get('column_description');
        $this->data['column_deploy_status'] = $this->language->get('column_deploy_status');


		$this->data['text_item_vpc'] = $this->language->get('text_item_vpc');
		$this->data['text_item_eip'] = $this->language->get('text_item_eip');

		$this->data['button_view'] = $this->language->get('button_view');
		$this->data['button_reorder'] = $this->language->get('button_reorder');
		$this->data['button_continue'] = $this->language->get('button_continue');

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}

		$this->data['orders'] = array();

		$order_total = $this->model_account_order->getTotalOrders();

		//each page whow 5 orders
		$results = $this->model_account_order->getOrders(($page - 1) * 5, 5);

		foreach ($results as $result) {
			$product_total = $this->model_account_order->getTotalOrderProductsByOrderId($result['order_id']);
			$voucher_total = $this->model_account_order->getTotalOrderVouchersByOrderId($result['order_id']);
            $order_info = $this->model_account_order->getOrder($result['order_id']);

            if ($order_info) {
                $products = $this->model_account_order->getOrderProducts($order_info['order_id']);
                $product_array=array();
                foreach ($products as $product) {
                    $option_data = array();

                    $options = $this->model_account_order->getOrderOptions($order_info['order_id'], $product['order_product_id']);

                    foreach ($options as $option) {
                        if ($option['type'] != 'file') {
                            $value = $option['value'];
                        } else {
                            $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
                        }

                        $option_data[] = array(
                            'name'  => $option['name'],
                            'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
                        );
                    }
                    $product_info = $this->model_catalog_product->getProduct($product['product_id']);
                    $product_deploy_info = $this->model_account_order->getOrderProductDeploy($result['order_id'],$product['product_id']);
                    if($product_deploy_info){
                        $app_name  =$product_deploy_info['app_name'];
                        $instance_type   = $product_deploy_info['instance_type'];
                        $price   = $product_deploy_info['price'];
                    }else{
                        $app_name  ="";
                        $instance_type   = "";
                        $price   = 0;
                    }

                    $product_image = $this->model_tool_image->resize($product_info['image'],50,50);
                    $product_array[] = array(
                        'name'     => $product['name'],
                        'app_name'     => $app_name,
                        'instance_type'     => $instance_type,
                        'model'    => $product['model'],
                        'option'   => $option_data,
                        'image'   => $product_image,
                        'quantity' => $product['quantity'],
                        'hour_price'               => $this->currency->format($this->tax->calculate($price, $this->config->get('config_tax_id'), $this->config->get('config_tax'))),
                        'month_price'               =>$this->currency->format($this->tax->calculate($price*720, $this->config->get('config_tax_id'), $this->config->get('config_tax')),2),
                        'return'   => $this->url->link('account/return/insert', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL'),
                        'href'   => $this->url->link('product/product', 'product_id=' . $product['product_id'], 'SSL')
                    );
                }
                $vpc_array = $this->model_account_order->getOrderVpc($result['order_id']);
                $eip_array = $this->model_account_order->getOrderEip($result['order_id']);
           }


            $vpc_list=array();
            foreach($vpc_array as $vpc){
                $vpc_list[]=array(
                    'vpc_image'                => $this->model_tool_image->resize('data/vpc_icon.jpg', $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')),
                    'vpc_name'                => $vpc['vpc_name'],
                    'vpc_type'                => $vpc['vpc_type'],
                    'hour_price'               => $this->currency->format($this->tax->calculate($vpc['price'], $this->config->get('config_tax_id'), $this->config->get('config_tax'))),
                    'month_price'               =>$this->currency->format($this->tax->calculate($vpc['price']*720, $this->config->get('config_tax_id'), $this->config->get('config_tax')),2),
                );
            }
            $eip_list=array();
            foreach($eip_array as $eip){
                $eip_list[]=array(
                    'eip_image'                => $this->model_tool_image->resize('data/eip_icon.jpg', $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')),
                    'eip_name'                => $eip['eip_name'],
                    'bandwidth'                =>$eip['bandwidth'],
                    'hour_price'               => $this->currency->format($this->tax->calculate($eip['price'], $this->config->get('config_tax_id'), $this->config->get('config_tax'))),
                    'month_price'               => $this->currency->format($this->tax->calculate($eip['price']*720, $this->config->get('config_tax_id'), $this->config->get('config_tax')),2),
                );
            }


            $app_status=$this->backend->get_order_form_info($result['order_id'],$this->customer->getEmail(),$this->customer->getPassPlain());

            if($app_status['status']=="finished"){
                $deploy_status= $this->language->get('order_status_finish');
            }
            if($app_status['status']=="deploying"){
                $deploy_status= $this->language->get('order_status_deploying');
            }
            if($app_status['status']=="failed"){
                $deploy_status= $this->language->get('order_status_failed');
            }
            if($app_status['status']=="404"){
                $deploy_status= $this->language->get('order_status_404');
            }
			$this->data['orders'][] = array(
				'order_id'   => $result['order_id'],
				'name'       => $result['firstname'] . ' ' . $result['lastname'],
				'status'     => $result['status'],
				'url'     => $result['url'],
				'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
				'products'   => ($product_total + $voucher_total),
				'product'   => $product_array,
				'vpc_array'   => $vpc_list,
				'eip_array'   => $eip_list,
				'hour_total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
				'month_total'      =>$this->currency->format($this->tax->calculate($result['total']*720, $this->config->get('config_tax_id'), $this->config->get('config_tax')),2),
				'href'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], 'SSL'),
				'reorder'    => $this->url->link('account/order', 'order_id=' . $result['order_id'], 'SSL'),
				'deploy_status' => $deploy_status
					
			);
		}

		$pagination = new Pagination();
		$pagination->total = $order_total;
		$pagination->page = $page;
		$pagination->limit = 5;
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('account/order', 'page={page}', 'SSL');

		$this->data['pagination'] = $pagination->render();

		$this->data['continue'] = $this->url->link('account/account', '', 'SSL');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_list.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/account/order_list.tpl';
		} else {
			$this->template = 'default/template/account/order_list.tpl';
		}

		$this->children = array(
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'
		);

		$this->response->setOutput($this->render());
	}

	public function info() {
		$this->language->load('account/order');

		if (isset($this->request->get['order_id'])) {
			$order_id = $this->request->get['order_id'];
		} else {
			$order_id = 0;
		}

		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');

			$this->redirect($this->url->link('account/login', '', 'SSL'));
		}

		$this->load->model('account/order');
		$this->load->model('catalog/product');
		$this->load->model('tool/image');

		$order_info = $this->model_account_order->getOrder($order_id);

		if ($order_info) {
			$this->document->setTitle($this->language->get('text_order'));

			$this->data['breadcrumbs'] = array();

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_home'),
				'href'      => $this->url->link('common/home'),
				'separator' => false
			);

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_account'),
				'href'      => $this->url->link('account/account', '', 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$url = '';

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('heading_title'),
				'href'      => $this->url->link('account/order', $url, 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_order'),
				'href'      => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$this->data['heading_title'] = $this->language->get('text_order');

			$this->data['text_order_detail'] = $this->language->get('text_order_detail');
			$this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
			$this->data['text_order_id'] = $this->language->get('text_order_id');
			$this->data['text_date_added'] = $this->language->get('text_date_added');
			$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
			$this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
			$this->data['text_payment_method'] = $this->language->get('text_payment_method');
			$this->data['text_payment_address'] = $this->language->get('text_payment_address');
			$this->data['text_history'] = $this->language->get('text_history');
			$this->data['text_comment'] = $this->language->get('text_comment');

			$this->data['column_name'] = $this->language->get('column_name');
			$this->data['column_model'] = $this->language->get('column_model');
			$this->data['column_quantity'] = $this->language->get('column_quantity');
			$this->data['column_price'] = $this->language->get('column_price');
			$this->data['column_total'] = $this->language->get('column_total');
			$this->data['column_action'] = $this->language->get('column_action');
			$this->data['column_date_added'] = $this->language->get('column_date_added');
			$this->data['column_status'] = $this->language->get('column_status');
			$this->data['column_comment'] = $this->language->get('column_comment');
			$this->data['column_description'] = $this->language->get('column_description');
			$this->data['column_deploy_status'] = $this->language->get('column_deploy_status');

			$this->data['button_return'] = $this->language->get('button_return');
			$this->data['button_continue'] = $this->language->get('button_continue');


            $this->data['ajax_action']=$this->url->link('checkout/success/getProductStatus');

            if ($order_info['invoice_no']) {
				$this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
			} else {
				$this->data['invoice_no'] = '';
			}

			$this->data['order_id'] = $this->request->get['order_id'];
			$this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));

			if ($order_info['payment_address_format']) {
				$format = $order_info['payment_address_format'];
			} else {
				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
			}

			$find = array(
				'{firstname}',
				'{lastname}',
				'{company}',
				'{address_1}',
				'{address_2}',
				'{city}',
				'{postcode}',
				'{zone}',
				'{zone_code}',
				'{country}'
			);

			$replace = array(
				'firstname' => $order_info['payment_firstname'],
				'lastname'  => $order_info['payment_lastname'],
				'company'   => $order_info['payment_company'],
				'address_1' => $order_info['payment_address_1'],
				'address_2' => $order_info['payment_address_2'],
				'city'      => $order_info['payment_city'],
				'postcode'  => $order_info['payment_postcode'],
				'zone'      => $order_info['payment_zone'],
				'zone_code' => $order_info['payment_zone_code'],
				'country'   => $order_info['payment_country']
			);

			$this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

			$this->data['payment_method'] = $order_info['payment_method'];

			if ($order_info['shipping_address_format']) {
				$format = $order_info['shipping_address_format'];
			} else {
				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
			}

			$find = array(
				'{firstname}',
				'{lastname}',
				'{company}',
				'{address_1}',
				'{address_2}',
				'{city}',
				'{postcode}',
				'{zone}',
				'{zone_code}',
				'{country}'
			);

			$replace = array(
				'firstname' => $order_info['shipping_firstname'],
				'lastname'  => $order_info['shipping_lastname'],
				'company'   => $order_info['shipping_company'],
				'address_1' => $order_info['shipping_address_1'],
				'address_2' => $order_info['shipping_address_2'],
				'city'      => $order_info['shipping_city'],
				'postcode'  => $order_info['shipping_postcode'],
				'zone'      => $order_info['shipping_zone'],
				'zone_code' => $order_info['shipping_zone_code'],
				'country'   => $order_info['shipping_country']
			);

			$this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

			$this->data['shipping_method'] = $order_info['shipping_method'];

			$this->data['products'] = array();

			$products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);

			foreach ($products as $product) {
                $version_str='';
                $product_info = $this->model_catalog_product->getProduct($product['product_id']);
                $product_deploy_info = $this->model_account_order->getOrderProductDeploy($this->request->get['order_id'],$product['product_id']);
                if($product_deploy_info){
                    $app_name  =$product_deploy_info['app_name'];
                    $instance_type   = $product_deploy_info['instance_type'];
                    $price   = $product_deploy_info['price'];
                }else{
                    $app_name  ="";
                    $instance_type   = "";
                    $price   = 0;
                }
                $product_image = $this->model_tool_image->resize($product_info['image'],50,50);

                $option_data = array();

				$options = $this->model_account_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);

				foreach ($options as $option) {
					if ($option['type'] != 'file') {
						$value = $option['value'];
					} else {
						$value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
					}


                    if($option['name']=='version'){
                        $version_str=$value;
                    }
					$option_data[] = array(
						'name'  => $option['name'],
						'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
					);
				}

                $app_status=$this->backend->get_order_form_info($this->request->get['order_id'],$this->customer->getEmail(),$this->customer->getPassPlain());


                $action= "";
                $status= "";
                $error_text= "";
                if($app_status['status']=='failed'&&!isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['status'])){
                    $status= "部署失败";
                }else{


                    if(isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['status'])){
                        if($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['status']=="finished"){
                            $status= "部署成功";
                            if(isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http'])){
                                $action=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http'];
                            }elseif(isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http2'])){
                                $action=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http2'];
                            }else{
                                $action=' ';
                            }
                            if(isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['https'])){
                                $action.=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['https'];
                            }if(isset($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http1'])){
                                $action.=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['http1'];
                            }
                        }
                        if($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['status']=="deploying"){
                            $status= $this->language->get('order_status_finish');
                        }
                        if($app_status['access'][$product['model'].str_replace('.','_',$version_str)]['status']=="failed") {
                            $status = $this->language->get('order_status_failed');
                            $error_text = $app_status['access'][$product['model'].str_replace('.','_',$version_str)]['error_text'];
                            if (strpos($error_text,'application')) {
                                $error_text = '不支持该应用程序类型';
                            }
                            if (strpos($error_text,'quotas')) {
                                $error_text = '超出配额限制.';
                            }
                        }
                    }else{
                        $status= $this->language->get('order_status_deploying');
                    }
                }

                $deploy_config=$this->model_catalog_product->getProductDeploy($product['product_id']);
                $total_time=(int)$deploy_config['installation_time'];
                $base_time= number_format((100/$total_time), 2, '.', '');
                $used_time=time()-strtotime($order_info['date_modified']);

                $value=floor(($used_time/$total_time)*100);
                if($value>98){
                    $value=98;
                }

                if(strpos($product_info['model'].str_replace('.','_',$version_str),'clouddesktop')){
                    $action2=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['mstsc'];
                    $action_array=explode(':',$action2);
                    $ip=$action_array[1];
                    $port=str_replace('\' target=\'_blank\'>mstsc /v','',$action_array[2]);
                    $action.='<br/><a href="index.php?route=common/creatrdp&type=yzm&ip='.$ip.'&port='.$port.'">下载登陆客户端</a>';
                }
                if(strpos($product_info['model'].str_replace('.','_',$version_str),'rtx')){
                    $action2=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['mstsc'];
                    $action_array=explode(':',$action2);
                    $ip=$action_array[1];
                    $port=str_replace('\' target=\'_blank\'>mstsc /v','',$action_array[2]);
                    $action.='<br/><a href="index.php?route=common/creatrdp&type=rtx&ip='.$ip.'&port='.$port.'">下载登陆客户端</a>';
                }
                if(strpos($product_info['model'].str_replace('.','_',$version_str),'gjpcyb')){

                    $action=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['mstsc'];
                    $action_array=explode(':',$action);
                    $ip=$action_array[1];
                    $port=str_replace('\' target=\'_blank\'>mstsc /v','',$action_array[2]);
                    $action='<a href="index.php?route=common/creatrdp&type=gjp&&ip='.$ip.'&port='.$port.'">下载登陆客户端</a>';
                }
                if(strpos($product_info['model'].str_replace('.','_',$version_str),'kdzhj')){
                    $action=$app_status['access'][$product['model'].str_replace('.','_',$version_str)]['mstsc'];
                    $action_array=explode(':',$action);
                    $ip=$action_array[1];
                    $port=str_replace('\' target=\'_blank\'>mstsc /v','',$action_array[2]);
                    $action='<a href="index.php?route=common/creatrdp&type=zhj&&ip='.$ip.'&port='.$port.'">下载登陆客户端</a>';
                }

				$this->data['products'][] = array(
                    'name'     => $product_info['name'],
                    'app_name'     => $app_name,
                    'instance_type'     => $instance_type,
                    'model'    => $product_info['model'].str_replace('.','_',$version_str),
                    'option'   => $option_data,
                    'image'   => $product_image,
                    'status'   => $status,
                    'error_text'   => $error_text,
                    'action'   => $action,
                    'proportion_value' =>$value ,
                    'base_time' =>$base_time ,
                    'deploy_info'   => json_decode($product_deploy_info['deploy_info'],true),
                    'hour_price'               => $this->currency->format($this->tax->calculate($price, $this->config->get('config_tax_id'), $this->config->get('config_tax'))),
                    'month_price'               => $this->currency->format($this->tax->calculate($price*720, $this->config->get('config_tax_id'), $this->config->get('config_tax')),2),
                    'return'   => $this->url->link('account/return/insert', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL'),
                    'href'   => $this->url->link('product/product', 'product_id=' . $product['product_id'], 'SSL')
				);
			}

			// Voucher
			$this->data['vouchers'] = array();

			$vouchers = $this->model_account_order->getOrderVouchers($this->request->get['order_id']);

			foreach ($vouchers as $voucher) {
				$this->data['vouchers'][] = array(
					'description' => $voucher['description'],
					'amount'      => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
				);
			}

			$this->data['totals'] = $this->model_account_order->getOrderTotals($this->request->get['order_id']);

			$this->data['comment'] = nl2br($order_info['comment']);

			$this->data['histories'] = array();

			$results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);

			foreach ($results as $result) {
				$this->data['histories'][] = array(
					'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
					'status'     => $result['status'],
					'comment'    => nl2br($result['comment'])
				);
			}

			$this->data['continue'] = $this->url->link('account/order', '', 'SSL');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/account/order_info.tpl';
			} else {
				$this->template = 'default/template/account/order_info.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
		} else {
			$this->document->setTitle($this->language->get('text_order'));

			$this->data['heading_title'] = $this->language->get('text_order');

			$this->data['text_error'] = $this->language->get('text_error');

			$this->data['button_continue'] = $this->language->get('button_continue');

			$this->data['breadcrumbs'] = array();

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_home'),
				'href'      => $this->url->link('common/home'),
				'separator' => false
			);

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_account'),
				'href'      => $this->url->link('account/account', '', 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('heading_title'),
				'href'      => $this->url->link('account/order', '', 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_order'),
				'href'      => $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL'),
				'separator' => $this->language->get('text_separator')
			);

			$this->data['continue'] = $this->url->link('account/order', '', 'SSL');

			$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
		}
	}

}
?>
